<?php
/**
 * Description of commentclass
 *
 * @author Flame
 */
class comment {


    function  __construct($id,$person,$mess,$tempo) {
        $this->id = $id;
        $this->person = $person;
        $this->mess = $mess;
        $this->time = $tempo;
    }

    function erase()
    {
        global $cfg,$db,$user;

        if($cfg->get('comments_save_method') == 1)
        {
            if($user->mod) $sql = "UPDATE comments SET delete = 1 WHERE id = ".$this->id." LIMIT 1";
            else $sql = "UPDATE comments SET delete = 1 WHERE id = ".$this->id." AND id_da = ".$user->id." LIMIT 1";
        }
        else if($cfg->get('comments_save_method') == 2)
        {
            if($user->mod) $sql = "DELETE FROM comments WHERE id = ".$this->id." LIMIT 1";
            else $sql = "DELETE FROM comments WHERE id = ".$this->id." AND id_da = ".$user->id." LIMIT 1";
        }
        if($db->query($sql)) return true;
        return false;
    }

    function mod($mess)
    {
        global $db,$user;

        if($user->mod) $sql = "UPDATE comments SET testo = '".funzione_per_testo($mess)."' WHERE id = '".$this->id."' LIMIT 1";
        else $sql = "UPDATE comments SET testo = '".funzione_per_testo($mess)."' WHERE id = '".$this->id."' AND id_da = ".$user->id." LIMIT 1";

        if($db->query($sql)) return true;
        return false;
    }
}
?>
